<?php
define('PROJECT_ROOT', __DIR__ . '/../');
define('REST_PHP_VERSION', '3.1');
define('DIR_LIB', PROJECT_ROOT . 'lib');
define('DIR_RESTPHP', PROJECT_ROOT . 'src');
define('DIR_BUILD', PROJECT_ROOT . 'test/php');
define('DIR_BUILD_TARGET', PROJECT_ROOT . 'test/runtime/target');
define('HTTP_VERSION', '1.1');
define('CONTENT_TYPE', 'application/json');
define('SYS_TIME', time());
define('SYS_MICRO_TIME', microtime(true));

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/Rest.php';

spl_autoload_register(array('restphp\core\RestLoad','load'));

// 构建
#\restphp\aop\AspectBuilder::build();

// 测试：需要与构建分开执行，即构建结果需要在新进程中才生效
#$aopExample = new \example\AopExample();
#$aopExample->test2();
#echo $aopExample->test(8);

//\restphp\Rest::build();

# MySQL replace
$_DB_MYSQL = array(
    'DB_PREFIX' => '', //表前缀
    'Def_Select'	=> array(	//查询库，一般是从库或只读库
        'dbhost'	=> '127.0.0.1',
        'dbport'	=> 3306,
        'dbuser'	=> 'forfun',
        'dbpass'	=> 'ww2G#@Ad2wm8Lk',
        'dbname'	=> 'for_fun',
        'charset'	=> 'UTF8',
        'dbtype'	=> 1,
        'linktype'	=> 1,
        'fetchtype'	=> 1
    ),
    'Def_Update'	=> array(	//有数据修改权限的库，一般指主库
        'dbhost'	=> '127.0.0.1',
        'dbport'	=> 3306,
        'dbuser'	=> 'forfun',
        'dbpass'	=> 'ww2G#@Ad2wm8Lk',
        'dbname'	=> 'for_fun',
        'charset'	=> 'UTF8',
        'dbtype'	=> 1,
        'linktype'	=> 1,
        'fetchtype'	=> 1
    )
);

function test()
{
    return date('Y-m-d');
}

$testRepository = new \example\db\TestRecordRepository();
$record = new \example\db\TestRecord();
$record->setType(5);
$record->setUserId(2);
$testRepository->save($record, true);

$newRecord = \restphp\driver\RestRepositoryHelper::autoFillValue($record);
var_export($newRecord->getId());